<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>

<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>付款管理</title>
		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		
		<link rel="stylesheet" href="static/ace/css/bootstrap.css" />
		<link rel="stylesheet" href="static/ace/css/font-awesome.css" />
		
		<!-- text fonts -->
		<link rel="stylesheet" href="static/ace/css/ace-fonts.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
				<link rel="stylesheet" type="text/css" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css">
		<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
		<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
		<script type="text/javascript">
			$(top.hangge());
		</script>
	</head>
		 
	<body class="no-skin">
		<!-- /section:basics/navbar.layout -->
<!-- 		<div class="main-container" id="main-container"> -->
			
<!-- 		</div> -->
	<div id="receipt"></div>
<!-- 	<div id="receiptgrid"></div> -->
	</body>
	<script type="text/javascript">
	Ext.onReady(function () {
		var store = Ext.create('Ext.data.Store', {
			fields: ["id",
			         "receipt_app_code",
			         "settlement_dept",
			         "payment_app_dept",
			     	"dept_business_type",
			    	"payment_dept",
			    	"due_bank",
			    	"payment_method",
			    	"remark",
			         "usd",
			         "rmb",
			         "txtrmb",
			         "txtusd"],
			pageSize: 10,  //页容量5条数据
			//是否在服务端排序 （true的话，在客户端就不能排序）
			remoteSort: false,
			remoteFilter: true,
			proxy: {
				type: 'ajax',
				url: '<%=basePath%>receiptMgr/findAllReceiptInfo',
				reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
					type: 'json', //返回数据类型为json格式
					root: 'result.list',  //数据
					totalProperty: 'result.total' //数据总条数
				}
			},
			sorters: [{
				property: 'ordeId',
				direction: 'desc'
			}],
			autoLoad: true
		});
		
		var store1 = Ext.create('Ext.data.Store', {
			fields: ["id",
			         "receipt_app_code",
			         "invoice_bill_code",
			         "receivables_invoice_code",
			         "payment_app_dept",
			         "CURRENCY",
			         "total_amount",
			         "early_receipt",
			         "amount",
			         "remaining_balance",
			         "is_advance",
			         "SALER_NAME",
			         "offset_usd",
			         "offset_rmb",
			         "decuctible_usd",
			         "decuctible_rmb",
			         "usd",
			         "rmb",
			         "is_fin_audi"
			         ],
			pageSize: 10,  //页容量5条数据
			//是否在服务端排序 （true的话，在客户端就不能排序）
			remoteSort: false,
			remoteFilter: true,
			proxy: {
				type: 'ajax',
				url: '<%=basePath%>receiptMgr/findReceiptInfo',
				reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
					type: 'json', //返回数据类型为json格式
					root: 'result.list',  //数据
					totalProperty: 'result.total' //数据总条数
				}
			},
			sorters: [{
				property: 'ordeId',
				direction: 'desc'
			}],
			autoLoad: true
		});
		
		  var c1 = Ext.create('Ext.container.Container', {
				layout: 'column',
				defaults: { labelAlign: 'left', labelWidth: 60 },
				items: [
					{id:"startDate1",xtype: 'textfield', name: 'startDate1',columnWidth: 1/5,padding: '5px',fieldLabel: '缴款单号'},
					{id:"startDate2",xtype: 'textfield', name: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '单位'},
					{id:"startDate3",xtype: 'textfield', name: 'startDate3', columnWidth:  1/5,padding: '5px', fieldLabel: '收款日期'},
					{id:"startDate4",xtype: 'textfield', name: 'startDate4', columnWidth:  1/5,padding: '5px', fieldLabel: '收款部门'},
					
					{xtype: "button",minWidth:70,padding: '5px',icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "查询缴款单",handler: function(){
						var receipt_app_code= Ext.getCmp('startDate1').getValue();
						var settlement_dept= Ext.getCmp('startDate2').getValue();
// 						var payment_app_dept= Ext.getCmp('startDate3').getValue();
						var payment_app_dept= Ext.getCmp('startDate4').getValue();
						var store = Ext.getCmp('grid').getStore();
						store.on('beforeload', function(store,options) {  
					            var new_params = {  
					            		receipt_app_code:receipt_app_code,settlement_dept:settlement_dept,payment_app_dept:payment_app_dept
					            };  

					            Ext.apply(store.proxy.extraParams,new_params);  
					        });  
					        store.load();  
					}}
					]
			});
		var grid = Ext.create('Ext.grid.Panel', {
// 			renderTo: "receipt",
			id:'grid',
			store: store,
			title:"收款对应信息内容",
			height: 330,
			stripeRows:true,
			columnLines: true,
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
				{text: 'ID', dataIndex: 'ID',hidden:true},
				{text: '缴款单号', dataIndex: 'receipt_app_code', align: 'left', maxWidth: 100 ,locked: true},
				{text: '单位', dataIndex: 'settlement_dept', maxWidth: 200 ,locked:true},
				{text: '美元', dataIndex: 'txtusd', maxWidth: 80},
				{text: '人民币', dataIndex: 'txtrmb', maxWidth: 80},
				{text: '收款美元', dataIndex: 'usd', maxWidth: 80},
				{text: '收款人民币', dataIndex: 'rmb', maxWidth: 80},
				{text: '收款日期', dataIndex: 'riverPort', maxWidth: 80},
				{text: '收款部门', dataIndex: 'payment_app_dept', maxWidth: 80},
				{text: 'dept_business_type', dataIndex: 'dept_business_type',hidden:true},
				{text: 'payment_dept', dataIndex: 'payment_dept',hidden:true},
				{text: 'due_bank', dataIndex: 'due_bank',hidden:true},
				{text: 'payment_method', dataIndex: 'payment_method',hidden:true},
				{text: 'remark', dataIndex: 'remark',hidden:true},
				
				
			],
			bbar: [{
				xtype: 'pagingtoolbar',
 				store: store,
				displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
				emptyMsg: "没有数据",
				beforePageText: "当前页",
				afterPageText: "共{0}页",
				displayInfo: true
			}],
			
			tbar:[{text: '生成制单导出', icon: '../plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
	    		   var records = grid.getSelectionModel().getSelection();
				   	 if(records.length==0){
				     			Ext.Msg.alert("提示","请至少选择一条记录");return;
				     		}
				   	var receipt_app_code = records[0].data.receipt_app_code;
				   	var settlement_dept = records[0].data.settlement_dept;
				   	var payment_app_dept = records[0].data.payment_app_dept;
				   	var dept_business_type = records[0].data.dept_business_type;
				   	var payment_dept = records[0].data.payment_dept;
				   	var due_bank = records[0].data.due_bank;
				   	var payment_method = records[0].data.payment_method;
				   	var remark = records[0].data.remark;
				   	
				   	document.location.href="<%=basePath%>common/export/exportExcel?exportType="+"Receipt"+"&receipt_app_code="+receipt_app_code+"&settlement_dept="+settlement_dept+"&payment_app_dept="+payment_app_dept+"&dept_business_type="+dept_business_type+"&payment_dept="+payment_dept+"&due_bank="+due_bank+"&payment_method="+payment_method+"&remark="+remark;
// 				   	exportFile("Receipt",records[0].data.receipt_app_code,records[0].data.id)
	    	   }}],
			listeners: {
				'itemclick': function (view, record, item, index, e) {
					var store = Ext.getCmp('receiptgrid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		receipt_app_code:record.data.receipt_app_code
				            };  

				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
				        store.load();  
				}
			},

		});
		var receiptgrid = Ext.create('Ext.grid.Panel', {
// 			renderTo: "receiptgrid",
			store: store1,
			id:'receiptgrid',
			height: 330,
			title:"收款内容",
			stripeRows:true,
			columnLines: true,
			selModel:Ext.create('Ext.selection.CheckboxModel',{checkOnly:false}),
			columns: [
				{text: 'id', dataIndex: 'id',hidden:true},
				{text: 'offset_usd', dataIndex: 'offset_usd',hidden:true},
				{text: 'offset_rmb', dataIndex: 'offset_rmb',hidden:true},
				{text: 'decuctible_rmb', dataIndex: 'decuctible_rmb',hidden:true},
				{text: 'decuctible_usd', dataIndex: 'decuctible_usd',hidden:true},
				{text: '缴款单号', dataIndex: 'receipt_app_code', align: 'left', maxWidth: 100 ,locked: true},
				{text: '业务编号', dataIndex: 'invoice_bill_code', maxWidth: 200 ,locked:true},
				{text: '发票号', dataIndex: 'receivables_invoice_code', maxWidth: 80},
				{text: '部门', dataIndex: 'payment_app_dept', maxWidth: 80},
				{text: '币制', dataIndex: 'CURRENCY', align: 'left', minWidth: 80},
				{text: '完税金额', dataIndex: 'total_amount', maxWidth: 80},
				{text: '前期收款', dataIndex: 'early_receipt', maxWidth: 80},
				{text: '本次收款', dataIndex: 'amount', maxWidth: 80},
				{text: '余额', dataIndex: 'remaining_balance', maxWidth: 80},
				{text: '是否预收', dataIndex: 'is_advance', maxWidth: 80},
				{text: '销售员', dataIndex: 'SALER_NAME', maxWidth: 80},
				{text: '复核状态', dataIndex: 'is_fin_audi', maxWidth: 80}
			],
			bbar: [{
				xtype: 'pagingtoolbar',
 				store: store1,
				displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
				emptyMsg: "没有数据",
				beforePageText: "当前页",
				afterPageText: "共{0}页",
				displayInfo: true
			}],
			listeners: {
				'itemclick': function (view, record, item, index, e) {
//                Ext.MessageBox.alert("标题", record.data.cataId);
				}
			},
			tbar: [{text: '收款复核', icon: '../plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
				 var records = receiptgrid.getSelectionModel().getSelection();
			   	 if(records.length==0){
			     			Ext.Msg.alert("提示","请选择一条记录");return;
			     		}
			   	var arr = [];
       			Ext.each(records,function(item){
       				obj = {
       						id:item.data.id
       				};
       				arr.push(obj);
       			});
       			var array = JSON.stringify(arr);
			   	Ext.Ajax.request({
						url:'<%=basePath%>receiptMgr/updateReceiptInfo',
						params:{
							array:array
						},
						timeout:5000,
						success:function(response){
							store.load();
							Ext.Msg.alert("成功","复核成功!");
						},
						failure:function(response){
							Ext.Msg.alert("错误","请求异常!");
						}
					});
		       }
		    	   },{text: '冲抵处理', icon: '../plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
		    		   var records = receiptgrid.getSelectionModel().getSelection();
					   	 if(records.length==0){
					     			Ext.Msg.alert("提示","请选择一条记录");return;
					     		}
					   	if(records.length>1){
			     			Ext.Msg.alert("提示","只能选择一条记录");return;
			     		}
					   	
					   	if(records[0].data.offset_usd.toString()!=null && records[0].data.offset_usd.toString()!=""||records[0].data.offset_rmb.toString()!=null && records[0].data.offset_rmb.toString()!=""){
					   		Ext.Msg.alert("提示","已经冲账，不能再次冲账");return;
					   	}
					   	if(records[0].data.is_fin_audi=="未审核"){
					   		Ext.Msg.alert("提示","未审核，不能冲账");return;
					   	}
						Ext.Ajax.request({
							url:'<%=basePath%>receiptMgr/strikeBalance',
							params:{
								id:records[0].data.id,usd:records[0].data.usd,rmb:records[0].data.rmb,decuctible_usd:records[0].data.decuctible_usd,decuctible_rmb:records[0].data.decuctible_rmb
							},
							timeout:5000,
							success:function(response){
								store1.load();
								Ext.Msg.alert("成功","冲账成功!");
							},
							failure:function(response){
								Ext.Msg.alert("错误","请求异常!");
							}
						});
		    	   }},]
		});
		 var panel = new Ext.Panel({
	            frame: true,
// 	            layout:"form",
// 	            width: 260,
// 	            height: 130,
// 	            labelWidth: 70,
	            title: "查询/复核",
	            renderTo:"receipt",
	            items:[c1,grid,receiptgrid],

	            
	        });
// 		 function exportFile(type,receipt_app_code,id){
// 			 alert(id),
// // 				var rs=receiptgrid.getSelectionModel().getSelection();
// //					var arr = [];
// // 				var ids = "";
// // 					Ext.each(rs,function(item){
// // 						ids+= item.data.id+",";
// // 					});
<%-- 			    document.location.href="<%=basePath%>common/export/exportExcel?exportType="+type+"&receipt_app_code="+receipt_app_code+"&id"+id; --%>
// 			}
	});
	
	</script>
</html>